<?php
namespace app\admin\model;
use think\Model;

class Orders extends model{
    function findid($id){
        $res = db('orders')->where('order_id',$id)->find();
		return $res;
    }
    // function findzhonglei1($id){
    //     $res = db('orders')->where('order_id',$id)->where('bet',1)->where('colums',2)->find();
	// 	return $res;
    // }
    // function findzhonglei2($id){
    //     $res = db('orders')->where('order_id',$id)->where('bet',1)->where('colums',1)->find();
	// 	return $res;
    // }
    
    function finallred($bet,$colums,$oid){
        $res = db('orders')->where('order_id',$oid)->where('bet',$bet)>where('colums',$colums)->select();
		return $res;
    }
    function finduid($uid){
		$res = db('orders')->where('uid',$uid)->select();
		return $res;
    }
    function findandicap($andicap){
        $res = db('orders')->distinct(true)->field('order_id')->where('andicap',$andicap)->select();
        return $res;
    }
    function findbetcolums($bet,$colums){
        $res = db('orders')->where(["bet"=>$bet ,"colums"=>$colums])->select();
        return $res;
    }
    function findbetbetscolums($bet,$colums,$bets){
        $res = db('orders')->where(['bet'=>$bet,'colums'=>$colums,'bets'=>$bets])->select();
        return $res;        
    }
    function findall(){
        $res = db('orders')->select();
        return $res;
    }
    function findcount(){
            $datatime = model('openplate')->finddata();
            for($i=0;$i<10;$i++){
                $res[$i] = 0;
            }
            $res[0] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('bet',1)->where('datatime',$datatime)->count();
        
            $res[1] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('bet',2)->where('datatime',$datatime)->count();
        
            $res[2] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('bet',3)->where('datatime',$datatime)->count();
            
            $res[3] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('bet',4)->where('datatime',$datatime)->count();
           
            $res[4] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('bet',">=",8)->where('bet',"<=",9)->where('datatime',$datatime)->count();
            
            $res[5] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('bet',6)->where('datatime',$datatime)->count();
         
            $res[6] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('datatime',$datatime)->where('bet','in',[10,11,12,5])->count();
           
            $res[7] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('bet',7)->where('datatime',$datatime)->count();
          
            $res[8] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('bet',">=",14)->where('bet',"<=",15)->where('datatime',$datatime)->count();
          
            $res[9] = db('orders o2')->join('ordered o1','o1.id=o2.order_id','LEFT')->field('o2.*,o1.datatime')->where('bet','in',[9,13])->where('datatime',$datatime)->count();
            
            return $res;
    }
}